/* USER CODE BEGIN Header */
/**
 ******************************************************************************
 * @file           : MLCD.h
 * @brief          : Header for MLCD.c file.
 *                   This file contains the common defines of the application.
 ******************************************************************************
 * @attention
 *
 * Copyright (c) [2021] [Fudan Microelectronics]
 * THIS SOFTWARE is licensed under Mulan PSL v2.
 * can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 *
 ******************************************************************************
 */
/* USER CODE END Header */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MLCD_H
#define __MLCD_H

#ifdef __cplusplus
extern "C"
{
#endif

    /* Includes ------------------------------------------------------------------*/

#include "fm33le0xx_fl.h"

    /* Private includes ----------------------------------------------------------*/
    /* USER CODE BEGIN Includes */

    /* USER CODE END Includes */

    /* Exported types ------------------------------------------------------------*/
    /* USER CODE BEGIN ET */

    typedef struct
    {
        const uint8_t FontWidth;
        const uint8_t FontHeight;
        const uint16_t *data;
    } FontType;

    extern FontType Font_6x8;
    extern FontType Font_7x10;
    extern FontType Font_11x18;
    extern FontType Font_16x26;

#define MLCD_DMA_USE (1)          /* user -SPI DMA conf[use or disable] */
#define MLCD_MULTIPLE_REFRESH (0) /* user -refresh way[multiple line or single line] */

#define CS_SET FL_GPIO_SetOutputPin(GPIOB, FL_GPIO_PIN_8)
#define CS_RESET FL_GPIO_ResetOutputPin(GPIOB, FL_GPIO_PIN_8)
#define DISP_SET FL_GPIO_SetOutputPin(GPIOB, FL_GPIO_PIN_3)
#define DISP_RESET FL_GPIO_ResetOutputPin(GPIOB, FL_GPIO_PIN_3)

#define MLCD_HEIGHT 128
#define MLCD_WIDTH 128
#define MLCD_DIS_BUFF_SIZE ((MLCD_HEIGHT * MLCD_WIDTH * 3 / 8) + 256 + 2)

#define MLCD_WRITE_CMD (0x01)
#define BIT_VCOM (0x02)
#define BIT_CLEAR (0x04)

    typedef enum
    {
        MLCD_FAIL = 0U,
        MLCD_PASS = !MLCD_FAIL
    } MLCD_ErrorStatus;

    typedef enum
    {
        BLACK = 0b000,
        RED = 0b001,
        GREEN = 0b010,
        YELLOW = 0b011,
        BLUE = 0b100,
        MAGENTA = 0b101,
        CYAN = 0b110,
        WHITE = 0b111
    } mlcd_color;

    typedef struct
    {
        bool msg_transport;
        bool msg_refresh_busy;
    } mlcd_msg_t;

    typedef struct
    {
        uint8_t Buffer[MLCD_DIS_BUFF_SIZE]; /* screen refresh buff -> 128+128*128 [256 is line addr and dmy] */
        mlcd_msg_t msg;
    } mlcd_t;

    /* USER CODE END ET */

    /* Exported constants --------------------------------------------------------*/
    /* USER CODE BEGIN EC */

    /* USER CODE END EC */

    /* Exported macro ------------------------------------------------------------*/
    /* USER CODE BEGIN EM */

    /* USER CODE END EM */

    /* Exported functions prototypes ---------------------------------------------*/
    /* USER CODE BEGIN EFP */

    void mlcd_clear(void);
    void mlcd_init(void);
    void mlcd_memset_buff(void);
    void mlcd_draw_pixel(uint8_t pixel_x, uint8_t pixel_y, mlcd_color pixel_color);
    void mlcd_refresh(void);
    void mlcd_semaphore_frame(void);
    void drawBox(int x, int y, int width, int height, mlcd_color color);
    void drawFrame(int x, int y, int width, int height, mlcd_color color);
    void mlcd_WriteChar(char ch, uint8_t pixel_x, uint8_t pixel_y, FontType Font, mlcd_color color);
    void mlcd_WriteString(const char *str, uint8_t pixel_x, uint8_t pixel_y, FontType Font, mlcd_color color);

    /* USER CODE END EFP */

    /* Private defines -----------------------------------------------------------*/

    /* USER CODE BEGIN Private defines */

    /* USER CODE END Private defines */

#ifdef __cplusplus
}
#endif

#endif /* __MLCD_H */

/************************ (C) COPYRIGHT FMSH *****END OF FILE****/
